package com.tbit.uqbike.client.service.impl;

import com.tbit.uqbike.client.constant.MemberCardConstant;
import com.tbit.uqbike.client.dao.core.VipCardLogDao;
import com.tbit.uqbike.client.pojo.VipCardLog;
import com.tbit.uqbike.client.pojo.vo.VipLogDot;
import com.tbit.uqbike.client.service.VipCardLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @Author: chen
 * @Description: 会员卡
 * @Date: 创建于 9:22 2020/7/7
 */
@Service
public class VipCardLogServiceImpl implements VipCardLogService {
    @Autowired
    private VipCardLogDao vipCardLogDao;

    @Override
    public List<VipLogDot> queryPage(Integer accountId, Integer userId, Integer pageNO,
                                     Integer rowCount) {
        Map<String, Object> map = new HashMap<>();
        map.put("accountId", accountId);
        map.put("userId", userId);
        map.put("page", (pageNO - 1) * rowCount);
        map.put("rowCount", rowCount);
        return vipCardLogDao.queryPage(map);
    }

    @Override
    public Integer queryCount(Integer accountId, Integer userId) {
        Map<String, Object> map = new HashMap<>();
        map.put("accountId", accountId);
        map.put("userId", userId);
        return vipCardLogDao.queryCount(map);
    }

    @Override
    public void add(VipCardLog vipCardLog) {
        vipCardLog.setBuyTime(new Date());

        vipCardLogDao.add(vipCardLog);
    }

    @Override
    public VipCardLog getByOrderNO(String orderNO) {

        return vipCardLogDao.getByOrderNO(orderNO);
    }

    @Override
    public void editPay(VipCardLog vipCardLog) {
        vipCardLogDao.editPay(vipCardLog);
    }

    @Override
    public List<VipCardLog> getById(Integer accountId, Integer userId) {
        Map<String, Object> map = new HashMap<>();
        map.put("accountId", accountId);
        map.put("userId", userId);
        return vipCardLogDao.getById(map);
    }

    @Override
    public List<VipCardLog> getByTime(Integer accountId, Integer userId) {
        Map<String, Object> map = new HashMap<>();
        map.put("accountId", accountId);
        map.put("userId", userId);
        return vipCardLogDao.getByTime(map);
    }

    @Override
    public VipCardLog getVipCardByUserId(Integer accountId, Integer userId) {
        return vipCardLogDao.getVipCardByUserId(accountId, userId);
    }

    @Override
    public VipLogDot getVaild(Integer accountId, Integer userId, Integer feeId) {
        Map<String, Object> map = new HashMap<>();
        map.put("accountId", accountId);
        map.put("userId", userId);
        map.put("feeId", feeId);
        return vipCardLogDao.getVaild(map);
    }

    @Override
    public VipLogDot getUserVip(Integer accountId, Integer userId, Integer feeId) {
        VipLogDot vipLogDots = getVaild(accountId, userId, feeId);
        if (vipLogDots == null) {
            vipLogDots = getVaild(accountId, userId, MemberCardConstant.MACHINE_FEE_ALL);
        }
        return vipLogDots;
    }

    @Override
    public List<VipLogDot> getUserRide(Integer accountId, String startTime, String endTime) {
        Map<String, Object> map = new HashMap<>();
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        map.put("accountId", accountId);
        return vipCardLogDao.getUserRide(map);
    }

    @Override
    public boolean hasValidVipCard(Integer userId) {
        return vipCardLogDao.validVipCount(userId) > 0;
    }
}
